package helper

import (
	"fmt"
	"strconv"
	"dhfshop/utils/uuid"
)

func ModifyOrderId(oldOrderId int64) (newOrderId int64, err error) {
	oldOrderIdStr := strconv.FormatInt(oldOrderId, 10)
	prefix := Substr(oldOrderIdStr, 0, 4)
	tmpNewOrderId, e := uuid.GetSnowFlakeId(uuid.Worker)
	if e != nil {
	   err = e
	   return
	}
	tmpNewOrderIdStr := strconv.FormatInt(tmpNewOrderId, 10)
	newOrderIdStr := fmt.Sprintf("%s%s", prefix, tmpNewOrderIdStr[4:])
	newOrderId, err = strconv.ParseInt(newOrderIdStr, 10, 64)
	return
}

func CreateSpecOrderId(prefix string) (orderId int64, err error) {
	tmpOrderId, e := uuid.GetSnowFlakeId(uuid.Worker)
	if e != nil {
	   err = e
	   return
	}
	tmpOrderIdStr := strconv.FormatInt(tmpOrderId, 10)
	orderIdStr := fmt.Sprintf("%s%s", prefix, tmpOrderIdStr[4:])
	orderId, err = strconv.ParseInt(orderIdStr, 10, 64)
	return
}
